<template>
  <div id="main">
    <h2>员工管理</h2>
    <!-- <el-button type="primary" style="margin:20px" @click="handleOpen('添加员工',1)">添加员工</el-button> -->
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >

        <el-table-column
          label="序号"
          type="index"
          width="80"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="cooperationMerchantName"
          label="合作商户名称"
        />

        <el-table-column
          align="center"
          prop="cooperationUserName"
          label="联系人"
        />

        <el-table-column
          align="center"
          prop="cooperationCall"
          label="联系电话"
        />

        <el-table-column align="center" label="操作">
          <template slot-scope="Scope">
            <!-- <el-button type="primary" icon="el-icon-edit" @click="handleOpen('修改员工',2,Scope.row.cooperationId)">编辑</el-button> -->
            <el-button type="danger" icon="el-icon-delete" @click="handleDelete(Scope.row.cooperationId,Scope.row.cooperationMerchantName)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- <el-dialog title="" :close-on-click-modal="false" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <el-form ref="cooperation" :model="cooperation" label-position="top" :rules="rules">

        <el-form-item prop="cooperationMerchantName" label="合作商户名称" :label-width="formLabelWidth">
          <el-input v-model="cooperation.cooperationMerchantName" autocomplete="off" maxlength="20" show-word-limit />
        </el-form-item>
        <el-form-item prop="cooperationUserName" label="联系人" :label-width="formLabelWidth">
          <el-input v-model="cooperation.cooperationUserName" autocomplete="off" maxlength="20" show-word-limit />
        </el-form-item>
        <el-form-item prop="cooperationCall" label="联系电话" :label-width="formLabelWidth">
          <el-input v-model="cooperation.cooperationCall" maxlength="11" autocomplete="off" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">取 消</el-button>
        <el-button v-if="editType==2" type="primary" @click="handleUpdate('cooperation')">修 改</el-button>
        <el-button v-if="editType==1" type="primary" @click="handleAddUser('cooperation')">添 加</el-button>
      </div>
    </el-dialog> -->

  </div>

</template>
<script>
import { getAllCooperation, deleteCooperation } from '@/api/cooperation'
export default {

  data() {
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: false,
      dialogFormVisible: false,
      editType: 1, // 1 添加 2 修改
      formLabelWidth: '200px',
      searchTableInfo: ''
    }
  },
  computed: {

  },
  created() {
    this.fetchData()
  },
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    fetchData() {
    //   this.tableList = []
      this.listLoading = true
      getAllCooperation().then((data) => {
        this.list = data.obj
        this.listLoading = false
      })
    },
    handleDelete(id, username) {
      this.$confirm('确认删除该合作记录？合作商户名称为' + username).then(() => deleteCooperation(id).then((data) => {
        this.$notify({
          title: '操作成功',
          type: 'success'
        })
        const totalPage = Math.ceil((this.list.length - 1) / this.pagesize)
        const page = this.currentPage > totalPage ? totalPage : this.currentPage
        this.currentPage = this.currentPage < 1 ? 1 : page
        this.fetchData()
      }))
    }
  }
}
</script>

<style scoped>
#main{
  margin-left: 5px;
  margin-right: 5px;
}
#table-area{
  margin-left: 10px;
  margin-right: 10px;
}
</style>
